<template>
	<view class="content" style="background: linear-gradient(180deg, #91c8ec 0%, #F0F9FE 28.08%)">
		<tabar :current="3"></tabar>
		<view class="top">血糖血压小程序</view>
		
		<!-- 基本信息 -->
		<view class="mine__bg" style="padding-top: 140rpx;">	
		    <view class="mine__info" style="padding-top:95rpx;">
				<view class="containersss">
				    <view class="member-bg"  :style="{ backgroundImage: `url(${userInfo.token ? userInfo.member_level : 'https://tangmaibao.site/static/upload/f42b5b566c89345e/e83497a25fc61e7d.png'})`}"></view>
					<image class="mine__bg--avatar" mode="aspectFill" style="background:" v-if="!userInfo.token" src="/static/mine/avatar.png" @click="userInfo.token?setBase():$routers.routeToLogin(recommendId)"></image>
					<image class="mine__bg--avatar" mode="aspectFill" style="background:" v-if="userInfo.token" :src="userInfo.wx_icon?userInfo.wx_icon:'/static/mine/avatar.png'" @click="setBase()"></image>	
				</view>
		        
			   	<view class="mine__info--cell"  @click="userInfo.token?setBase():$routers.routeToLogin(recommendId)">
					<view class="mine__info--name flex-direction mt-20 ml-15">						   
					   <text>{{userInfo.token && userInfo.nickName?userInfo.nickName:'你好！晚上想吃啥'}}</text>				
						<view class="flex mt-30">
							<image style="width: 38rpx;height: 38rpx;"  src="/static/mine/male.png"  v-if="!userInfo.token"></image>
							<image style="width: 38rpx;height: 38rpx;"  :src="userInfo.gender =='男'?'/static/mine/male.png':'/static/mine/female.png'"  v-if="userInfo.token"></image>	
							<text class="ml-15" style="color: #666666;">{{userInfo.age?userInfo.age:'28'}}岁</text>
						</view>
					 </view>			 					
				</view> 
			</view>						 
		</view>

	    <!-- 订单信息 -->
	    <view class="mine__cell-wrap" >
			<view class="mine__order mine__cell border-radius" style="height: 190rpx;">						        
				<view class="flex justify-around pt-30 pb-30">
					<view class="flex flex-direction align-center align-center justify-center orders" @click="userInfo.token?routeToOrder(2):$routers.routeToLogin(recommendId)">
						<view class="text-xl mb-5">							
							<view class="round-badges" v-if="userInfo.order2>0">
							   <text>{{userInfo.order2?userInfo.order2:''}}</text>
							</view>						
						    <image style="width: 80rpx;height: 80rpx;"  src="/static/mine/wait_order1.png"></image>						
						</view>
						<view class="text-sm text-gray order_text mt-10">待发货</view>
					</view>							
					<view class="flex flex-direction align-center align-center justify-center orders" @click="userInfo.token?routeToOrder(3):$routers.routeToLogin(recommendId)">
						<view class="text-xl mb-5">
							<view class="round-badges" v-if="userInfo.order3>0">
							   <text>{{userInfo.order2?userInfo.order3:''}}</text>
							</view>	
						    <image style="width: 80rpx;height: 80rpx;"  src="/static/mine/wait_order3.png"></image>						
						</view>
						<view class="text-sm text-gray order_text mt-10">待收货</view>
					</view>					
					<view class="flex flex-direction align-center align-center justify-center orders" @click="userInfo.token?routeToOrder(4):$routers.routeToLogin(recommendId)">
						<view class="text-xl mb-5">
						   <image style="width: 80rpx;height: 80rpx;"  src="/static/mine/wait_order2.png"></image>							
						</view>
						<view class="text-sm text-gray order_text mt-10">已收货</view>
					</view>					
					<view class="flex flex-direction align-center align-center justify-center orders" @click="userInfo.token?routeToOrder(5):$routers.routeToLogin(recommendId)">
						<view class="text-xl mb-5">
						    <image style="width: 80rpx;height: 80rpx;"  src="/static/mine/wait_order4.png"></image>				
						</view>
						<view class="text-sm text-gray order_text mt-10">待评价</view>
					</view>												
				</view>
			</view>	 						
		</view>
		<view class="mine__cell mt-20 " style="background: #F0F9FE;">
			<view class="flex flex-direction  bg-white" style="border-radius: 18rpx;    margin: 0 25rpx;">
				   <view v-for="(item, key) in moduleList" :key="key" class="module-item">
					    <!-- 判断 openType -->
					         <button
					           v-if="item.openType === 'share'"
					           open-type="share"
					           @click.stop="share(item)"
					           class="btn-reset"
					         >
							 <view class="flex justify-between bg-white align-center text-center p-20">
							 	<view class="flex justify-center align-center text-center">
							 		 <image class="t-cell-icon-image mr-20" :src='item.icon' ></image>
									<view class="t-cell-text">{{ item.name }}</view>
							 	</view>
								<block>
								    <u-icon name="arrow-right" color="#c6d1e2" size="20"></u-icon>
								</block>
							 </view>
					          
					         </button>
						<view
						        v-else
						        @click="routeUrl(item)"
						      >
						        <t-cell
						          :title="item.name"
						          :icon="item.icon"
						          :item="item"
						          :token="userInfo.token"
						          :recommendId="recommendId"
						        />
						      </view>
				
					</view>
				 <!-- 分享按钮 -->
				  
			</view>			 
		</view>
		
		<view class="flex mt-30"  style="padding-bottom: 190rpx;" v-if="userInfo.token">
			<button class='bottom'  @click="layout">
				退出登录
			</button>
		</view>
		
		
		<!-- 弹框部分 -->
		<u-popup
		  :show="userInfo.token && userInfo.is_information==0"
		  mode="center"
		  round="20"
		  :closeOnClickOverlay="false"
		  @close="showPopup = false"
		>
		  <view class="popup-box">
			<image
			  class="popup-icon"
			  src="/static/images/info.png"
			  mode="aspectFit"
			></image>
			<text class="popup-title">请完善个人信息</text>
			<text class="popup-desc mt-30">为了提供更好的服务，请先完善您的个人资料。</text>
	
			<view class="btn-group">
			  <u-button
				type="primary"
				color="#6EBA44"
				shape="circle"
				@click="goCompleteInfo"
			  >去完善</u-button>
			</view>
		  </view>
		</u-popup>
			
			
			
		 
	  
	</view>
</template>
<script>
import tcell from "@/components/cell/index.vue";
	export default {
		components: {
		   "t-cell": tcell
		},
		data() {
			return {
				...getApp().globalData.config,
				userlevel:'普通会员',
				level_intro:'享受全场优惠，全场折扣',
				recommendId:'',
				userInfo:{},
				moduleList: '',
				banner_list:[],
				show:false
				
			}
		},
		onLoad(events) {
			console.log('events',events)
			if(events.recommendId){
				this.recommendId=events.recommendId
			}			
		},
		methods: {
			...getApp().globalData.funcion,
			
			//完善信息
			goCompleteInfo(){
				this.$routers.router('/pages/pagesuser/member_set/member_base','navigateTo') 
			},
			//设置信息
			setBase(){
				this.$routers.router('/pages/pagesuser/member_set/member_base','navigateTo') 
			},
			//退出登陆
			layout(){
				let that=this
				
				uni.showModal({
				    content: '确定退出吗?',
				    success: function (res) {
				        if (res.confirm) {
				            uni.clearStorageSync();
				            uni.showToast({
				            	title: '退出成功',
				            	duration: 3000
				            });	
				            console.log('ok')
				            setTimeout(function(){
				            	console.log('ok33')
				            	that.$routers.router('/pages/home/index','switchTab') 
				            },2000)
				        } else if (res.cancel) {
				            console.log('用户点击了取消');
				            // 在这里执行当用户点击取消后要进行的操作
				        }
				    }
				}).then(res => {
				    // 这里实际上是处理 Promise 的成功情况，但通常我们不需要在 showModal 中直接使用 .then()
				    // 因为 showModal 的成功回调已经处理了结果
				    console.log('Promise resolved', res); // 注意这里的 res 实际上是 undefined，因为 showModal 不直接返回结果对象
				}).catch(error => {
				    console.error('Error:', error);
				});
			},			
			//跳转订单
			routeToOrder(type){
				this.$routers.router('/pages/order/index?currentTab='+type,'navigateTo') 
			},
			routeUrl(item){
				console.log('o')
				if(item.openType=="navigateTo"){
					this.$routers.router(item.url,'navigateTo')
				}				
			},
			//分享
			onShareAppMessage(){
				return{
					provider:'weixin',
					title:'邀请好友使用糖脉宝小助手!',
					path:'/pages/mine/index?recommendId='+this.userInfo.id,//页面 path ，必须是以 / 开头的完整路径
					imageUrl:'https://tangmaibao.site/static/upload/910207f2c872e9dd/4de16e13ba24964e.png',
					desc:'',
				}
			},
			
			
		},
		onShow() {	
			this.moduleList=[				
				{icon: '/static/mine/active.png', name: '个人档案', openType: 'navigateTo', isauth: false, url: '/pages/pagesuser/member_set/member_base'},
				{icon: '/static/mine/health.png', name: '健康报告',  openType: 'navigateTo', isauth: false, url: '/pages/pagesuser/report/index'},
				{icon: '/static/mine/points.png', name: '积分明细',  openType: 'navigateTo', isauth: false, url: '/pages/pagesuser/points/log'},
				{icon: '/static/mine/gift.png', name: '邀请有礼',  openType: 'share', isauth: false, url: ''}	    
			]
			let user_info=uni.getStorageSync('userInfo');
			let that=this;
			if(user_info){
				console.log()
				let obj_data={
					token:user_info.token,
				    login_type:'app'
				};
				this.$http.getUser(obj_data).then(res=>{				
					if(res.resCode=='9999'){
						uni.setStorageSync('userInfo',res.data);	
					    that.userInfo=res.data						
						let moduleList= this.moduleList				
						this.moduleList=moduleList						
					}				
				})				
			}else{
				 that.userInfo=''
			}
			
			
		}
		
		
		
	}
</script>

<style>
  @import "./index.css";
</style>
